//
//  MainViewController.m
//  List
//
//  Created by cocoazxj@163.com on 15/3/23.
//  Copyright (c) 2015年 handcool. All rights reserved.
//

#import "MainViewController.h"
#import "SubTable.h"
#import "TableModel.h"

@interface MainViewController ()
@property (nonatomic, strong) NSArray *mArray;
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setViewContent];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/* ******************************
 加载plist中的数据：
 1.首先获取.plist文件的路径
 2.使用arrayWithContentsOfFile函数读取文件
 3.
 ***************************** */
- (NSArray *)mArray
{
    if(!_mArray) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@".plist"];
        NSArray *array = [NSArray arrayWithContentsOfFile:path];
        NSMutableArray *m = [NSMutableArray array];
        for(NSDictionary *d in array)
        {
            [m addObject:[TableModel tableModel:d]];
        }
        _mArray = m;
    }
    return _mArray;
}

- (void)setViewContent
{
    for (int i = 0; i < self.mArray.count; i ++)
    {
        NSLog(@"------------%d",i);
        int num = i%3;                          // 0,1,2 num=0,1,2; 3,4,5 num=0,1,2;
        int row = i/3;                          // 0,1,2 row=0; 3,4,5 row=1;
        CGFloat x = 20*(num+1) + 80*(num);
        CGFloat y = 30*(row+1) + 100*row;
        SubTable *sub = [SubTable subTable:self.mArray[i]];
        sub.frame = CGRectMake(x, y, 80, 120);
        [self.view addSubview:sub];
    }
}
@end
